package com.mxchip.livestarmobile.mobile.duobeiyun;


import com.duobeiyun.paassdk.media.DBIVideoFrameCustom;
import com.duobeiyun.paassdk.media.DBVideoSource;
import com.duobeiyun.paassdk.media.MediaType;
import com.mxchip.livestarmobile.mobile.util.Log.MyLog;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author : create by yanggaosheng$
 * @time : 2019-10-10$
 * @des :  自定义视频源$
 **/
public class CustomVideoSource implements DBVideoSource {

    private Map<String, DBIVideoFrameCustom> frameCustomMap = new ConcurrentHashMap<>();

    @Override
    public void onVideoSourceInit(String deviceName, DBIVideoFrameCustom dbiVideoFrameCustom) {
        if (null == deviceName || "".equals(deviceName)) {
            deviceName = "";
        }
        MyLog.logD(MyLog.CUSTOM_VIDEO_SOURCE_MODEL, "CustomVideoSource::" + "onVideoSourceInit: " + deviceName);
        frameCustomMap.put(deviceName, dbiVideoFrameCustom);
    }

    @Override
    public void onVideoSourceStart(String deviceName) {
        //开始预览
    }

    @Override
    public void onVideoSourcePause(String deviceName) {
        //结束预览
    }

    @Override
    public void onVideoSouceDestroy(String deviceName) {
        if (null == deviceName || "".equals(deviceName)) {
            deviceName = "";
        }
        frameCustomMap.remove(deviceName);
    }

    //tips:该方法是第一个的调用的方法,所以预先是有哪些设备；需要业务自己做处理；如果不同的设备有不同的数据源；则按设备区分
    @Override
    public int getDBMediaFrameType(String deviceName) {
//        if ("dd3".equals(deviceName)) {
        return MediaType.DBMediaFrameType.H264.type;
//        }
//        return MediaType.DBMediaFrameType.NV21.type;
    }

    public Map<String, DBIVideoFrameCustom> getFrameCustomMap() {
        return frameCustomMap;
    }
}
